package com.zenith.edu.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zenith.edu.mapper.EduForumLikeMapper;
import com.zenith.edu.po.domain.EduForumLike;
import com.zenith.edu.po.dto.EduForumLikeDTO;
import com.zenith.edu.po.vo.EduForumLikeVO;
import com.zenith.edu.service.EduForumLikeService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class EduForumLikeServiceImpl extends ServiceImpl<EduForumLikeMapper, EduForumLike> implements EduForumLikeService {
    
    @Override
    public EduForumLikeVO createForumLike(EduForumLikeDTO dto) {
        EduForumLike forumLike = new EduForumLike();
        BeanUtils.copyProperties(dto, forumLike);
        this.save(forumLike);
        
        EduForumLikeVO vo = new EduForumLikeVO();
        BeanUtils.copyProperties(forumLike, vo);
        return vo;
    }
    
    @Override
    public EduForumLikeVO getForumLikeById(Long id) {
        EduForumLike forumLike = this.getById(id);
        if (forumLike == null) {
            return null;
        }
        
        EduForumLikeVO vo = new EduForumLikeVO();
        BeanUtils.copyProperties(forumLike, vo);
        return vo;
    }
    
    @Override
    public EduForumLikeVO updateForumLike(EduForumLikeDTO dto) {
        EduForumLike forumLike = new EduForumLike();
        BeanUtils.copyProperties(dto, forumLike);
        this.updateById(forumLike);
        
        EduForumLikeVO vo = new EduForumLikeVO();
        BeanUtils.copyProperties(forumLike, vo);
        return vo;
    }
    
    @Override
    public boolean deleteForumLike(Long id) {
        return this.removeById(id);
    }
    
    @Override
    public List<EduForumLikeVO> getForumLikeList() {
        List<EduForumLike> forumLikeList = this.list();
        return forumLikeList.stream().map(forumLike -> {
            EduForumLikeVO vo = new EduForumLikeVO();
            BeanUtils.copyProperties(forumLike, vo);
            return vo;
        }).collect(Collectors.toList());
    }
}